package com.zihao.blog.module.user.controller;


import com.zihao.blog.module.user.entity.Admin;
import com.zihao.blog.module.user.service.AdminService;
import com.zihao.blog.result.Result;
import com.zihao.blog.validator.group.GetList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 管理员表 前端控制器
 * </p>
 *
 * @author 子豪
 * @since 2020-12-24
 */
@RestController
@RequestMapping("/user/admin")
public class AdminController {

    @Autowired
    private AdminService adminService;

    @PostMapping("/list")
    public Result<Admin> list(@Validated(GetList.class) @RequestBody Admin admin) {
        List<Admin> list = adminService.list();
        return Result.ok().data(list);
    }

    @PostMapping("/get/{id}")
    public Result getById(@PathVariable String id) {
        return Result.ok().data(adminService.getById(id));
    }

    @DeleteMapping("delete")
    public Result deleteById(@PathVariable String id) {
        adminService.removeById(id);
        return Result.ok();
    }

}

